﻿using Longbow.ComponentModel;
using System.ComponentModel;
using System.Threading.Tasks;

namespace Microsoft.AspNetCore.Authorization
{
    /// <summary>
    /// BootstrapAdmin 授权要求类
    /// </summary>
    [LicenseProvider(typeof(LgbLicenseProvider))]
    internal class BootstrapAdminLicenseRequirement : AuthorizationHandler<BootstrapAdminLicenseRequirement>, IAuthorizationRequirement
    {
        /// <summary>
        /// 处理授权要求方法
        /// </summary>
        /// <param name="context"></param>
        /// <param name="requirement"></param>
        /// <returns></returns>
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, BootstrapAdminLicenseRequirement requirement)
        {
            if (context.User.Identity.IsAuthenticated)
            {
                if (LicenseManager.IsLicensed(typeof(BootstrapAdminLicenseRequirement))) context.Succeed(this);
            }
            return Task.CompletedTask;
        }
    }
}
